// Copyright (c) 2021 Presto Labs Pte. Ltd.
// Author: xguo

#pragma once

#include <cstdio>
#include <memory>

#include <rapidjson/document.h>

#include "coin2/exchange/base/order/order.h"
#include "coin2/exchange/dydx_futures/symbology/product.h"

namespace coin2::exchange::dydx_v3::order_v3 {

class DydxFuturesV3Parser : public base::order::BaseParser {
 public:
  const ParseResult& ParseRawMessage(const RawMessage& msg) override;
  AccountBalance ParseBalance(const JsonValue& doc) override;
  AccountPosition ParsePosition(const JsonValue& doc) override;

 private:
  void ParseSubmitResponse();
  void ParseCancelResponse();
  void ParseRestOrders();
  void ParseRestFillOrders();
  void ParseRestAccountBalance();
  void ParseRestAccountPosition();
  void ParseWsMessage();
  void ParseRateLimit();

  void ParseWsOrderInfoList(const JsonDocument& document);
  void ParseWsFillInfoList(const JsonDocument& document);
  void ParseWsPosition(const JsonDocument& document);
  void ParseOrderInfo(const JsonValue& data, coin::proto::ProductOrderElement* order);
  void ParseFillInfo(const JsonValue& data, coin::proto::ProductFillElement* fill);

 private:
  bool is_account_balance_initialized_ = false;
  bool is_account_position_initialized_ = false;
  std::string native_symbol_;
};

}  // namespace coin2::exchange::dydx_v3::order_v3
